package beavers.studio.golfberry.screens;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import beavers.studio.golfberry.fields.GolfTabField;

public class GolfScreen extends MainScreen {
	//Screen enum
	public static class ID {
		//Enumerations
		public static final ID HOME 	= new ID(0, "Home");
		public static final ID GROUP 	= new ID(1, "Groups");
		public static final ID MAP 		= new ID(2, "Maps");
		public static final ID PIC 		= new ID(3, "Snapshots");
		public static final ID QUIZ 	= new ID(4, "Quiz");
		public static final ID SCORE 	= new ID(5, "Scorecard");
		public static final ID REGISTER	= new ID(6, "Registration");
		
		protected ID(int id, String name) {
			//Save
			m_ID 	= id;
			m_Name	= name;
			
			//Load icon
			m_Icon = Bitmap.getBitmapResource("header/icon" + m_ID + ".png");
		}
		
		public static ID[] values() {
			return s_Values;
		}
		
		public final int getID()	{	return m_ID;	}
		public Bitmap getIcon() 	{	return m_Icon;	}
		public String getLabel()	{	return m_Name;	}
		
		//Members
		protected int		m_ID;
		protected String 	m_Name;
		protected Bitmap	m_Icon;
		
		//Static
		protected static final ID[] s_Values = new ID[] {
			HOME, 
			GROUP, 
			MAP, 
			PIC, 
			QUIZ, 
			SCORE, 
			REGISTER  };
	}
	
	public GolfScreen(ID id) {
		//Save data
		m_ID = id;
		
		//Create tab field
		m_GolfTab 							= new GolfTabField(m_ID.getID());
		HorizontalFieldManager TabManager 	= new HorizontalFieldManager();
		TabManager.add(m_GolfTab);
		add(TabManager);
		
		//Set as focused
		m_GolfTab.setFocus();
	}
	
	protected boolean navigationMovement(int dx, int dy, int status, int time) {
		//If right
    	if (dx > 0) {
    		//Next tab
    		m_GolfTab.next();
    		m_GolfTab.getManager().invalidate();
    	} else if (dx < 0) {
    		//Previous tab
    		m_GolfTab.previous();
    		m_GolfTab.getManager().invalidate();
    	}
    	
    	//Disable default navigation
    	return true;
    }
	
	protected boolean navigationClick(int status, int time) {
		//If tab is focused
		if (m_GolfTab.isFocus()) {
			//Get selected screen
			ID Selected = m_GolfTab.getScreenID();
			if (Selected != m_ID) {
				//Change screen if not null
				GolfScreen NewScreen = ScreenFactory.createScreen(Selected);
				if (NewScreen != null) {
					//Change screen
					UiApplication.getUiApplication().popScreen(this);
					UiApplication.getUiApplication().pushScreen(NewScreen);
					
					//Consume
					return true;
				}
			}
		}		
		
		//Don't consume
		return false;
	}
	
	//Members
	protected ID			m_ID;
	protected GolfTabField 	m_GolfTab;
}
